<template>
  <vxe-modal height="90vh" title="货架信息" v-model="hjVisible" width="90%" showFooter show-zoom resize>
    <!-- 顶部搜索 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="货架名称" prop="hjName">
        <el-input size="mini"
                  v-model="queryParams.hjName"
                  placeholder="请输入货架名称"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格 -->
<!--    <el-table ref="table"-->
<!--              height="60vh" :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"-->
<!--              v-loading="loading" :data="hjglList" @selection-change="handleSelectionChange">-->
<!--      <el-table-column label="序号" align="center" type="index" :index="indexMethod"/>-->
<!--      <el-table-column label="所属仓库" align="center" prop="ckName"/>-->
<!--      <el-table-column label="货架名称" align="center" prop="hjName"/>-->
<!--      <el-table-column label="货架备注" align="center" prop="hjBz"/>-->
<!--      <el-table-column label="分层信息" align="center" width="300">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            type="primary"-->
<!--            size="mini"-->
<!--            @click="handleButtonClick(scope.row)"-->
<!--          >查看-->
<!--          </el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--    </el-table>-->

    <merge-table style="height: 60vh" v-loading="loading" :table-data="hjglList" :merge-arr="hjMergeArr">
      <el-table-column label="序号" align="center" type="index" :index="indexMethod"/>
      <el-table-column label="所属仓库" align="center" prop="ckName"/>
      <el-table-column label="货架名称" align="center" prop="hjName"/>
      <el-table-column label="货架备注" align="center" prop="hjBz"/>
      <el-table-column label="分层信息" align="center" width="300">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            @click="handleButtonClick(scope.row)"
          >查看
          </el-button>
        </template>
      </el-table-column>
    </merge-table>

    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 分层信息 -->
    <vxe-modal height="60vh" title="分层信息" v-model="fcVisible" width="60%" showFooter show-zoom resize>

      <merge-table style="height: 46vh" v-loading="loadings" :table-data="fcglList" :merge-arr="mergeArr">
        <el-table-column label="序号" align="center" type="index"/>
        <el-table-column label="所属货架" align="center" prop="hjName"/>
        <el-table-column label="分层名称" align="center" prop="fcName"/>
        <el-table-column label="分层备注" align="center" prop="fcBz"/>
      </merge-table>

<!--      <el-table :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"-->
<!--                height="45vh" v-loading="loadings" :data="fcglList">-->
<!--        <el-table-column label="序号" align="center" type="index" :index="indexMethod"/>-->
<!--        <el-table-column label="所属货架" align="center" prop="hjName"/>-->
<!--        <el-table-column label="分层名称" align="center" prop="fcName"/>-->
<!--        <el-table-column label="分层备注" align="center" prop="fcBz"/>-->
<!--      </el-table>-->

    </vxe-modal>

  </vxe-modal>
</template>

<script>
import {listHjgl} from "@/api/wzgl/hjgl";
import Fcgl from "@/views/wzgl/ckgl/FcGl.vue";
import {listFcgl} from "@/api/wzgl/fcgl";
import MergeTable from "@/components/MergeTable/index.vue";

export default {
  name: "HjXx",
  components: {MergeTable, Fcgl},
  data() {
    return {
      hjMergeArr: ['ckName'],
      mergeArr: ['hjName'],
      fcVisible: false,//分层弹窗
      loadings: false,
      fcglList: [], //分层的表格
      ckGlId: null,//打开后的对应仓库ID
      dyCkList: null, //打开后的对应仓库信息
      //弹窗是否打开
      hjVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 货架管理表格数据
      hjglList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        ckglId: this.ckGlId,
        ckName: null,
        hjName: null,
      },
      // 表单参数
      form: {},
      fcQueryParams: {
        pageNum: 1,
        pageSize: 50,
        hjglId: null,
        hjName: null,
        fcName: null,
        fcBz: null
      },
    };
  },
  created() {

  },
  methods: {
    //打开分层信息
    handleButtonClick(row) {
      this.fcVisible = true
      this.loadings = true;
      this.fcQueryParams.hjglId = row.hjglId
      listFcgl(this.fcQueryParams).then(response => {
        this.fcglList = response.rows;
        this.loadings = false;
      });
    },
    /** 自定义编号 */
    indexMethod(index) {
      let pageNum = this.queryParams.pageNum - 1;
      if ((pageNum !== -1 && pageNum !== 0)) {
        return (index + 1) + (pageNum * this.queryParams.pageSize);
      } else {
        return (index + 1)
      }
    },
    //打开
    handleOpen(row) {
      this.dyCkList = row //对应仓库信息
      this.ckGlId = row.ckglId
      this.hjVisible = true
      this.getList()
    },
    /** 查询货架管理列表 */
    getList() {
      this.loading = true;
      this.queryParams.ckglId = this.ckGlId
      listHjgl(this.queryParams).then(response => {
        this.hjglList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        hjglId: null,
        ckglId: this.dyCkList.ckglId,
        ckName: this.dyCkList.ckName,
        hjName: null,
        hjBz: null
      };
      this.resetForm("formDialog");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.hjglId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
  }
};
</script>

<style scoped>

</style>
